import 'package:get/get.dart';
import 'package:pornhub_app/model/mine/mine_tabconfigs_model.dart';

import '../../../../http/http_service.dart';

class MineTabConfigController extends GetxController {
  var configs = [];
  int buyType = 0;
  bool buyStatus = false;
  int promoType = 0;
  bool promoStatus = false;
  String buyImg = '';
  String promoImg = '';

  Future getConfig() async {
    try {
      configs = await httpInstance.get(
          url: "sys/mineConfig", complete: MineTabconfigsModel.fromJson);
      if (configs.isEmpty) return;
      for (int i = 0; i < configs.length; i++) {
        if (configs[i].type == 1) {
          buyType = configs[i].type;
          buyStatus = configs[i].status;
          buyImg = configs[i].img;
        } else if (configs[i].type == 2) {
          promoType = configs[i].type;
          promoStatus = configs[i].status;
          promoImg = configs[i].img;
        }
      }
      update();
    } catch (_) {
      return null;
    }
  }

  @override
  void onInit() {
    super.onInit();
    getConfig();
  }
}
